package com.testes.umov.util;

import java.util.Date;

public class TimeHelper {

	private Date startDate = null;
	private Date endDate = null;
	private int operations = 0;
	
	public TimeHelper(int _operations) {
		this.operations = _operations;
	}
	
	public void startClock() {
		this.startDate = new Date();
	}
	
	public void stop() {
		this.endDate = new Date();
	}
	
	public float getOperationTimeInMilliSeconds()
	{
		if(startDate != null && endDate != null && startDate.getTime() <= endDate.getTime() && this.operations > 0) {
			long time = this.endDate.getTime() - this.startDate.getTime();
			return (float)time / (float)this.operations;
		}
		
		return -1;
	}
	
	public long getTotalTimeInMilliSeconds()
	{
		if(startDate != null && endDate != null && startDate.getTime() <= endDate.getTime()) {
			return  this.endDate.getTime() - this.startDate.getTime();
		}
		
		return -1;
	}
}
